using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Text;
using ECommerce.DAL;


namespace Entity
{
    /// <summary>
    /// This object represents the Private Fields of TblFavorites.
    /// </summary>

    [System.ComponentModel.DataObject]
    public class TblFavorites : DatabaseUtility
    {
        #region TblFavorites Private Fields


        Int32 _favoritesId;
        Int32 _userId;
        Int32 _productId;
        Boolean _isActive;
        Boolean _isDeleted;
        DateTime _createDate;

        #endregion
        #region TblFavorites Constractor
        /// <summary>
        /// Creates an empty object of TblFavorites. 
        /// This is mainly used to create a new instance of TblFavorites to add a new TblFavorites.
        /// </summary>
        public TblFavorites() { }


        /// <summary>
        /// Used to retrieve employee information from database, 
        /// which is also used by Update method to save information of an existing TblFavorites.
        /// </summary>
        public TblFavorites
        (
            Int32 favoritesId,
            Int32 userId,
            Int32 productId,
            Boolean isActive,
            Boolean isDeleted,
            DateTime createDate
        )
        {
            _favoritesId = favoritesId;
            _userId = userId;
            _productId = productId;
            _isActive = isActive;
            _isDeleted = isDeleted;
            _createDate = createDate;
        }

        #endregion
        #region TblFavorites Properties

        /***********************************************************************************************
                                    -- PROPERTIES --        
         Contains all the properties representing the data fields of the current entity.
         ***********************************************************************************************/

        /// <summary>
        /// This is the Primary key value of the FavoritesId, which can't be assigned from the application,
        /// to ensure the data consistancy, by not letting the user to change the PK_TblFavorites to update the data of an another TblFavorites instance.
        /// For view or updation purpose, every TblFavorites will be retrieved thru the proper 'Get' method.
        /// </summary>

        public Int32 FavoritesId
        {
            get { return _favoritesId; }
        }


        public Int32 UserId
        {
            get { return _userId; }
            set { _userId = value; }
        }

        public Int32 ProductId
        {
            get { return _productId; }
            set { _productId = value; }
        }

        public Boolean IsActive
        {
            get { return _isActive; }
            set { _isActive = value; }
        }

        public Boolean IsDeleted
        {
            get { return _isDeleted; }
            set { _isDeleted = value; }
        }

        public DateTime CreateDate
        {
            get { return _createDate; }
            set { _createDate = value; }
        }


        #endregion
        #region TblFavorites Static Methods
        /************************************************************************************
                                    -- CREATE METHOD (STATIC) --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public static Int32 CreateNewTblFavorites
        (
            Int32 userId,
            Int32 productId,
            Boolean isActive,
            Boolean isDeleted,
            DateTime createDate
        )
        {
            //creating an empty TblFavorites object
            TblFavorites tblFavorites = new TblFavorites();
            tblFavorites.UserId = userId;
            tblFavorites.ProductId = productId;
            tblFavorites.IsActive = isActive;
            tblFavorites.IsDeleted = isDeleted;
            tblFavorites.CreateDate = createDate;

            return TblFavorites.CreateNewTblFavorites(tblFavorites);
        }

        /************************************************************************************
                 -- UPDATE METHODS (STATIC) --
        *************************************************************************************/

        /************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        There the two types of paramaters will be passed here.
         * a. Primary key paramater: it should be Sql type, as we will bind the primary key property for the view controls (form view, details view etc) as datakey.
         * b. Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static bool UpdateTblFavorites
        (
            Int32 favoritesId,
            Int32 userId,
            Int32 productId,
            Boolean isActive,
            Boolean isDeleted,
            DateTime createDate
        )
        {
            TblFavorites tblFavorites = TblFavorites.GetTblFavoritesByFavoritesId(favoritesId);

            tblFavorites.UserId = userId;
            tblFavorites.ProductId = productId;
            tblFavorites.IsActive = isActive;
            tblFavorites.IsDeleted = isDeleted;
            tblFavorites.CreateDate = createDate;

            return TblFavorites.UpdateTblFavorites(tblFavorites);
        }

        /************************************************************************************
                         -- DELETE METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        ****************************************************************************/
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static bool DeleteTblFavorites
        (
            Int32 favoritesId
        )
        {
            //Validate Input
            if (favoritesId <= GetFavoritesIdMinValue)
                throw (new ArgumentOutOfRangeException("favoritesId"));

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddParameterToSqlCmd(sqlCmd, "@FavoritesId", SqlDbType.Int, 0, ParameterDirection.Input, favoritesId);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_DELETETBLFAVORITES);
            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return (returnValue == 0 ? false : true);

        }

        /// <summary>
        /// Deletes a set of employees from the database.
        /// </summary>
        public static bool DeleteTblFavoritesList(System.Collections.Generic.List<Int32> favoritesIdListToDelete)
        {
            //Validate Input
            foreach (Int32 favoritesId in favoritesIdListToDelete)
                if (favoritesId <= GetFavoritesIdMinValue)
                    throw (new ArgumentOutOfRangeException("favoritesId"));

            //performing deletion operation //

            string xmlString = FormatXMLForIdArray(favoritesIdListToDelete);

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddParameterToSqlCmd(sqlCmd, "@FavoritesIdList", SqlDbType.Xml, xmlString.ToString().Length, ParameterDirection.Input, xmlString.ToString());
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_DELETETBLFAVORITESLIST);
            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return (returnValue == favoritesIdListToDelete.Count ? true : false);
        }

        /************************************************************************************
                                 -- GET BY PRIMARY METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        Retrives an Employee from database, based on it's primary key.
        To view or update an employee, everytime we must have to use this type of 'get' method, 
        since we don't have direct access to the Primary key value for assigning value.
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        /*****************************************************************************/
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static TblFavorites GetTblFavoritesByFavoritesId(Int32 favoritesId)
        {
            if (favoritesId <= GetFavoritesIdMinValue)
                throw (new ArgumentOutOfRangeException("favoritesId"));

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@FavoritesId", SqlDbType.Int, 0, ParameterDirection.Input, favoritesId);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_GETTBLFAVORITESBYFAVORITESID);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblFavoritesCollectionFromReader);
            CustomCollection<TblFavorites> objCollection = ((CustomCollection<TblFavorites>)ExecuteReaderCmd(sqlCmd, test));

            if (objCollection.Count > 0)
                return objCollection[0];
            else
                return null;
        }

        /************************************************************************************
                         -- GET BY FOREIGN KEY METHODS --
        *************************************************************************************/

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public static CustomCollection<TblFavorites> GetTblFavoritesByUserId(Int32 userId)
        {
            if (userId <= GetUserIdMinValue)
                throw (new ArgumentOutOfRangeException("userId"));

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@UserId", SqlDbType.Int, 0, ParameterDirection.Input, userId);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_GETTBLFAVORITESBYUSERID);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblFavoritesCollectionFromReader);
            CustomCollection<TblFavorites> objCollection = ((CustomCollection<TblFavorites>)ExecuteReaderCmd(sqlCmd, test));

            if (objCollection.Count > 0)
                return objCollection;
            else
                return null;
        }

        /// <summary>
        /// Gets all the TblFavorites regarding 'PREFERRED_LANGUAGE_ID' foreign key.
        /// It supports efficient paging.
        /// </summary>
        /// <returns>A collection of TblFavorites.</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public static CustomCollection<TblFavorites> GetTblFavoritesByUserIdPaged(Int32 userId, String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            //Validate Input
            if (userId <= GetUserIdMinValue)
                throw (new ArgumentOutOfRangeException("userId"));

            if (orderBy == "")
                orderBy = "UserId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@UserId", SqlDbType.Int, 0, ParameterDirection.Input, userId);
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRowIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, maximumRows);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_GETTBLFAVORITESBYUSERIDPAGED);

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblFavoritesCollectionFromReader);
            CustomCollection<TblFavorites> objCollection = ((CustomCollection<TblFavorites>)ExecuteReaderCmd(sqlCmd, test));

            return objCollection;
        }

        /// <summary>
        /// This is a supporting method of 'GetEmployeeByPREFERRED_LANGUAGE_IDPagedPagedCountPaged' method.
        /// Used in paging, which returns the total number of records, returned from the ''GetEmployeeByReportsToPaged'' method (regardless of page size).
        /// Although we are not using the parameters, but we need the same signature as ''GetEmployeeByReportsToPaged'' to support paging.
        /// </summary>
        public static int GetTblFavoritesByUserIdPagedCount(Int32 userId, String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            //Validate Input
            if (userId <= GetUserIdMinValue)
                throw (new ArgumentOutOfRangeException("userId"));

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@UserId", SqlDbType.Int, 0, ParameterDirection.Input, userId);
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_GETTBLFAVORITESBYUSERIDPAGEDCOUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public static CustomCollection<TblFavorites> GetTblFavoritesByProductId(Int32 productId)
        {
            if (productId <= GetProductIdMinValue)
                throw (new ArgumentOutOfRangeException("productId"));

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@ProductId", SqlDbType.Int, 0, ParameterDirection.Input, productId);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_GETTBLFAVORITESBYPRODUCTID);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblFavoritesCollectionFromReader);
            CustomCollection<TblFavorites> objCollection = ((CustomCollection<TblFavorites>)ExecuteReaderCmd(sqlCmd, test));

            if (objCollection.Count > 0)
                return objCollection;
            else
                return null;
        }

        /// <summary>
        /// Gets all the TblFavorites regarding 'PREFERRED_LANGUAGE_ID' foreign key.
        /// It supports efficient paging.
        /// </summary>
        /// <returns>A collection of TblFavorites.</returns>
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, false)]
        public static CustomCollection<TblFavorites> GetTblFavoritesByProductIdPaged(Int32 productId, String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            //Validate Input
            if (productId <= GetProductIdMinValue)
                throw (new ArgumentOutOfRangeException("productId"));

            if (orderBy == "")
                orderBy = "ProductId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@ProductId", SqlDbType.Int, 0, ParameterDirection.Input, productId);
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRowIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, maximumRows);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_GETTBLFAVORITESBYPRODUCTIDPAGED);

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblFavoritesCollectionFromReader);
            CustomCollection<TblFavorites> objCollection = ((CustomCollection<TblFavorites>)ExecuteReaderCmd(sqlCmd, test));

            return objCollection;
        }

        /// <summary>
        /// This is a supporting method of 'GetEmployeeByPREFERRED_LANGUAGE_IDPagedPagedCountPaged' method.
        /// Used in paging, which returns the total number of records, returned from the ''GetEmployeeByReportsToPaged'' method (regardless of page size).
        /// Although we are not using the parameters, but we need the same signature as ''GetEmployeeByReportsToPaged'' to support paging.
        /// </summary>
        public static int GetTblFavoritesByProductIdPagedCount(Int32 productId, String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            //Validate Input
            if (productId <= GetProductIdMinValue)
                throw (new ArgumentOutOfRangeException("productId"));

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@ProductId", SqlDbType.Int, 0, ParameterDirection.Input, productId);
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_GETTBLFAVORITESBYPRODUCTIDPAGEDCOUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        /************************************************************************************
                 -- GET ALL METHODS --
        *************************************************************************************/
        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static CustomCollection<TblFavorites> GetAllTblFavorites()
        {

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_GETALLTBLFAVORITES);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblFavoritesCollectionFromReader);
            CustomCollection<TblFavorites> objCollection = ((CustomCollection<TblFavorites>)ExecuteReaderCmd(sqlCmd, test));

            return objCollection;
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static CustomCollection<TblFavorites> GetAllTblFavoritesPaged(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            //Validate Input
            if (orderBy == "")
                orderBy = "FavoritesId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRowIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, maximumRows);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_GETALLTBLFAVORITESPAGED);

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblFavoritesCollectionFromReader);
            CustomCollection<TblFavorites> objCollection = ((CustomCollection<TblFavorites>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }

        [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static int GetAllTblFavoritesPagedCount(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_GETALLTBLFAVORITESPAGEDCOUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        #endregion
        #region Employee Instance Methods
        /************************************************************************************
                                    -- SAVE (INSERT/UPDATE) METHODS (INSTANCE) --
        *************************************************************************************/
        /// <summary>
        /// Saves (inserts and updates) an Employee into database.
        /// The insertion occur if the EmployeeId conatins default value.
        /// Otherwises it updates the Employee into the database, based on the primary key value stored in EmployeeId.
        /// This technique ensures an Employee will not be updated without having a valid EmployeeId.
        /// </summary>
        public bool Save()
        {
            if (FavoritesId <= GetFavoritesIdMinValue)
            {
                Int32 TempId = CreateNewTblFavorites(this);
                if (TempId > 0)
                {
                    _favoritesId = TempId;
                    return true;
                }
                else
                {
                    // error occurs
                    return false;
                }
            }
            else
            {	//This is a update Command
                return (UpdateTblFavorites(this));
            }

        }

        public static Int32 CreateNewTblFavorites(TblFavorites newTblFavorites)
        {
            // validate Parameters
            if (newTblFavorites == null)
                throw (new ArgumentNullException("newTblFavorites"));

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            int length = 0;
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);

            AddParameterToSqlCmd(sqlCmd, "@UserId", SqlDbType.Int, 0, ParameterDirection.Input, newTblFavorites.UserId);
            AddParameterToSqlCmd(sqlCmd, "@ProductId", SqlDbType.Int, 0, ParameterDirection.Input, newTblFavorites.ProductId);
            AddParameterToSqlCmd(sqlCmd, "@IsActive", SqlDbType.Bit, 0, ParameterDirection.Input, newTblFavorites.IsActive);
            AddParameterToSqlCmd(sqlCmd, "@IsDeleted", SqlDbType.Bit, 0, ParameterDirection.Input, newTblFavorites.IsDeleted);
            AddParameterToSqlCmd(sqlCmd, "@CreateDate", SqlDbType.DateTime, 0, ParameterDirection.Input, newTblFavorites.CreateDate);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_CREATENEWTBLFAVORITES);
            ExecuteScalarCmd(sqlCmd);
            return (Int32.Parse(sqlCmd.Parameters["@ReturnValue"].Value.ToString()));

        }
        /// <summary>
        /// Updates an TblFavorites instance to the database.
        /// </summary>
        public static bool UpdateTblFavorites(TblFavorites newTblFavorites)
        {
            // validate Parameters
            if (newTblFavorites == null)
                throw (new ArgumentNullException("newTblFavorites"));

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            int length = 0;
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);

            AddParameterToSqlCmd(sqlCmd, "@FavoritesId", SqlDbType.Int, 0, ParameterDirection.Input, newTblFavorites.FavoritesId);
            AddParameterToSqlCmd(sqlCmd, "@UserId", SqlDbType.Int, 0, ParameterDirection.Input, newTblFavorites.UserId);
            AddParameterToSqlCmd(sqlCmd, "@ProductId", SqlDbType.Int, 0, ParameterDirection.Input, newTblFavorites.ProductId);
            AddParameterToSqlCmd(sqlCmd, "@IsActive", SqlDbType.Bit, 0, ParameterDirection.Input, newTblFavorites.IsActive);
            AddParameterToSqlCmd(sqlCmd, "@IsDeleted", SqlDbType.Bit, 0, ParameterDirection.Input, newTblFavorites.IsDeleted);
            AddParameterToSqlCmd(sqlCmd, "@CreateDate", SqlDbType.DateTime, 0, ParameterDirection.Input, newTblFavorites.CreateDate);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBLFAVORITES_UPDATETBLFAVORITES);
            ExecuteScalarCmd(sqlCmd);
            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return (returnValue == 0 ? false : true);
        }
        #endregion

        #region TblFavorites Related Collections
        /// <summary>
        /// Creates and returns a strongly typed collection of Employee custom entity. 
        /// The colelction is created through iterating on the IdataReader object which contains Employee information, as a set of records, similar to tabular format.
        /// </summary>
        public static CollectionBase GenerateTblFavoritesCollectionFromReader(IDataReader returnData)
        {

            //creating the instance of Employee collection
            CustomCollection<TblFavorites> colTblFavorites = new CustomCollection<TblFavorites>();

            /************************* Architecure note:**********************************
             * Below code includes the null value functionality to retieve the data which has nill value in database end.
             * Design consideration:
             * Besides general data fields, special care should be taken for primary keys, to assign '0'/defaultvalue, rather passing 'Null' value in constructor parameter.
             * Although we are considering sqldb tyoe data for the current data container, but while retireving data from database end, through datareader object, we need to cast data reader objects using .net primitive data type, 
             * rather using sqldb type to cast, since data reader objects don't support sql db type to be casted.
             *****************************************************************************/

            //Iterating thriugh the data reader, to generate Employee collection.

            //getting the Employee collection by iterating thru the data reader
            while (returnData.Read())
            {
                //passing the TblFavorites constructor parameters from the current instance of data reader fields.
                TblFavorites newTblFavorites = new TblFavorites
                (
                    returnData["FavoritesId"] == System.DBNull.Value ? GetFavoritesIdMinValue : (Int32)returnData["FavoritesId"],
                    returnData["UserId"] == System.DBNull.Value ? 0 : (Int32)returnData["UserId"],
                    returnData["ProductId"] == System.DBNull.Value ? 0 : (Int32)returnData["ProductId"],
                    returnData["IsActive"] == System.DBNull.Value ? false : (Boolean)returnData["IsActive"],
                    returnData["IsDeleted"] == System.DBNull.Value ? false : (Boolean)returnData["IsDeleted"],
                    returnData["CreateDate"] == System.DBNull.Value ? DateTime.MinValue : (DateTime)returnData["CreateDate"]

                );
                //adding the Employee to the collection
                colTblFavorites.Add(newTblFavorites);
            }

            //returns the collection of Companys 
            return (colTblFavorites);
        }

        #endregion
        #region Constants and Default Values

        public static Int32 GetFavoritesIdMinValue
        {
            get
            {
                return 0;
            }
        }
        public static Int32 GetUserIdMinValue
        {
            get
            {
                return 0;
            }
        }
        public static Int32 GetProductIdMinValue
        {
            get
            {
                return 0;
            }
        }

        //create method related contants
        internal const string SP_TBLFAVORITES_CREATENEWTBLFAVORITES = "sp_TblFavorites_CreateNewTblFavorites";
        internal const string SP_TBLFAVORITES_UPDATETBLFAVORITES = "sp_TblFavorites_UpdateTblFavorites";
        internal const string SP_TBLFAVORITES_DELETETBLFAVORITES = "sp_TblFavorites_DeleteTblFavorites";
        internal const string SP_TBLFAVORITES_DELETETBLFAVORITESLIST = "sp_TblFavorites_DeleteTblFavoritesList";
        internal const string SP_TBLFAVORITES_GETTBLFAVORITESBYFAVORITESID = "sp_TblFavorites_GetTblFavoritesByFavoritesId";
        internal const string SP_TBLFAVORITES_GETTBLFAVORITESBYUSERID = "sp_TblFavorites_GetTblFavoritesByUserId";
        internal const string SP_TBLFAVORITES_GETTBLFAVORITESBYUSERIDPAGED = "sp_TblFavorites_GetTblFavoritesByUserIdPaged";
        internal const string SP_TBLFAVORITES_GETTBLFAVORITESBYUSERIDPAGEDCOUNT = "sp_TblFavorites_GetTblFavoritesByUserIdPagedCount";
        internal const string SP_TBLFAVORITES_GETTBLFAVORITESBYPRODUCTID = "sp_TblFavorites_GetTblFavoritesByProductId";
        internal const string SP_TBLFAVORITES_GETTBLFAVORITESBYPRODUCTIDPAGED = "sp_TblFavorites_GetTblFavoritesByProductIdPaged";
        internal const string SP_TBLFAVORITES_GETTBLFAVORITESBYPRODUCTIDPAGEDCOUNT = "sp_TblFavorites_GetTblFavoritesByProductIdPagedCount";
        internal const string SP_TBLFAVORITES_GETALLTBLFAVORITES = "sp_TblFavorites_GetAllTblFavorites";
        internal const string SP_TBLFAVORITES_GETALLTBLFAVORITESPAGED = "sp_TblFavorites_GetAllTblFavoritesPaged";
        internal const string SP_TBLFAVORITES_GETALLTBLFAVORITESPAGEDCOUNT = "sp_TblFavorites_GetAllTblFavoritesPagedCount";

        #endregion
    }
}
